package com.ffapp.demo.mapwindow;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.amap.api.maps.AMap;
import com.amap.api.maps.model.Marker;
import com.ffapp.demo.R;
import com.ffapp.demo.basis.BasisApp;
import com.ffapp.demo.bean.Troubleshoots;
import com.ffapp.demo.map.cluster.Cluster;


/**
 * Created by Teprinciple on 2016/8/23.
 * 地图上自定义的infowindow的适配器
 */
public class FatherWinAdapter implements AMap.InfoWindowAdapter, View.OnClickListener {

    private Context mContext = BasisApp.mContext;
    private Troubleshoots troubleshoots;
    private LinearLayout viewItem;
    private Marker marker;


    @Override
    public View getInfoWindow(Marker marker) {
        initData(marker);
        View view = initView();
        return view;
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }

    private void initData(Marker marker) {
        this.marker = marker;
        Cluster cluster = (Cluster) marker.getObject();
        troubleshoots = cluster.getClusterItems().get(0).getTroubleshoots();
    }

    @NonNull
    private View initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.view_infowindow_proof, null);

        TextView tvAddress = (TextView) view.findViewById(R.id.tv_address);
        TextView tvCheck = (TextView) view.findViewById(R.id.tv_check);
        TextView tvNorTrouble = (TextView) view.findViewById(R.id.tv_nor_trouble);
        TextView tvBigTrouble = (TextView) view.findViewById(R.id.tv_big_trouble);
        LinearLayout llAllDanger = (LinearLayout) view.findViewById(R.id.ll_all_danger);
        viewItem = (LinearLayout) view.findViewById(R.id.view_item);
        viewItem.setOnClickListener(this);

        tvAddress.setText(troubleshoots.getBuildName());
        switch (troubleshoots.getCheckStatus()){
            case "0":
                tvCheck.setText("（未排查）");
                tvCheck.setTextColor(mContext.getResources().getColor(R.color.base_text_red));
                llAllDanger.setVisibility(View.GONE);
                break;
            case "1":
                tvCheck.setText("（已排查）");
                tvCheck.setTextColor(mContext.getResources().getColor(R.color.base_blue));
                llAllDanger.setVisibility(View.VISIBLE);
                tvNorTrouble.setText(troubleshoots.getNormalTrouble()+"个");
                tvBigTrouble.setText(troubleshoots.getBigTrouble()+"个");
                break;
            case "non":
                tvCheck.setVisibility(View.GONE);
                llAllDanger.setVisibility(View.VISIBLE);
                tvNorTrouble.setText(troubleshoots.getNormalTrouble()+"个");
                tvBigTrouble.setText(troubleshoots.getBigTrouble()+"个");
                break;
        }


        return view;
    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.view_item:  //详情
//                ToastUtil.show(mContext, "被点击了");
//                ActivityTool.skipActivity(mContext, CompreActivity.class);
                break;
        }
    }

}
